var t = getApp();

Page({
    data: {
        server: t.server,
        serverUrl: t.serverUrl,
        id: null,
        lv2: null,
        list: null,
        curr: null
    },
    onLoad: function(t) {
        this.setData({
            id: t.id,
            lv2: t.lv2Id,
            curr: 0
        }), this.loadList(), this.loadMem();
    },
    addWatch: function() {
        t.request({
            url: t.server + "/videoApi/addWatchCount ",
            method: "POST",
            data: {
                vid: this.data.list[this.data.curr].id,
                token: t.token
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {}
        }), wx.setNavigationBarTitle({
            title: this.data.list[this.data.curr].title
        });
    },
    loadMem: function() {
        var a = this;
        t.request({
            url: t.server + "/userApi/getFactoryInfo",
            method: "POST",
            data: {
                token: t.token
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                a.setData({
                    company: t.data.result.info.company_name
                });
            }
        });
    },
    loadList: function() {
        var a = this;
        t.request({
            url: t.server + "/videoApi/getVideoCategoryInfo",
            method: "POST",
            data: {
                token: t.token,
                page_size: 999,
                cur_page: 1,
                cid: this.data.lv2
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var e = 0, n = 0, r = t.data.result.data || [], i = !0, o = !1, d = void 0;
                try {
                    for (var s, c = r[Symbol.iterator](); !(i = (s = c.next()).done); i = !0) {
                        var u = s.value;
                        u.share_icon || (u.share_icon = "/static/albums/album-icon.png"), u.share_content || (u.share_content = "新款发布"), 
                        u.id === a.data.id && (e = n), u.durationTxt = a.fmt(u.duration), n++;
                    }
                } catch (t) {
                    o = !0, d = t;
                } finally {
                    try {
                        !i && c.return && c.return();
                    } finally {
                        if (o) throw d;
                    }
                }
                a.setData({
                    list: r,
                    curr: e
                }), a.addWatch();
            }
        });
    },
    fmt: function(t) {
        if (t = parseInt(t), !isNaN(t) && t || (t = 0), !t) return "00:00";
        for (var a = [], e = 3; e > 0; e--) {
            var n = t % 60;
            if (a.splice(0, 0, n > 10 ? n : "0" + n), 0 === (t = parseInt(t / 60)) && e <= 2) break;
        }
        return a.join(":");
    },
    switchPrd: function(t) {
        var a = t.currentTarget.dataset.index;
        this.setData({
            curr: a
        }), this.addWatch();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = this.data.list[this.data.curr];
        return {
            title: t.share_content || "新款发布",
            path: "/pages/video/detail/detail?id=" + t.id + "&lv2Id=" + this.data.lv2
        };
    }
});